<?php
class Brand_Search{
    
  const TABLE_NAME = 'product_brand';
  const TABLE_NAME_SEARCH = 'type_brand';
  const TABLE_NAME_SEARCH_SECOND ='product_type';
    /**
     *单例对象
     */    
   public static $singletonObjects = array();
   
   /**
    * 获取单例对象
    */
   public static function getInstance(){
       $className = __CLASS__;
       if( !isset( self::$singletonObjects[$className] ) )
		{
			self::$singletonObjects[$className] = new self( );
		}

		return self::$singletonObjects[$className];
       
       
   }
   /**
    *根据产品类型获取产品品牌
    * @param type $TId
    * 
    */
    public function getProductBrand( $TId ){
         
          $arrType = Common::getMysql()->get( self::TABLE_NAME_SEARCH_SECOND ,array( 'TId' => $TId ) );
          if( $arrType['FId'] ==0 ){
              
              /**
               * 获得本类下的所有子类id
               */
              $productBrandId = Common::getMysql()->getlist( self::TABLE_NAME_SEARCH_SECOND ,array( 'FId' => $TId) );
              
              $brandId = array();
              foreach( $productBrandId as $key =>$value){
                 $brandId[] .= $value['TId']; 
              }
             /**
              * 根据产品子类Id获取产品品牌的Id
              */
             
              $productBId = Common::getMYsql()->getMultiList( self::TABLE_NAME_SEARCH , 'TId' , $brandId ); 
              /**
               * 根据品牌id获得品牌名称
               */
              $BId = array();
             
              foreach ( $productBId as $key => $value){
                  $BId[] .= $value['BId'];
              }
              
              $productBrand = Common::getMYsql()->getMultiList( self::TABLE_NAME , 'BId' , $BId );

             
          }
          else{
              $productBrandId = Common::getMysql()->getList( self::TABLE_NAME_SEARCH , array( 'TId' => $TId) );
              $brandId = array();
              foreach( $productBrandId as $key => $value ){
                 $brandId[] .= $value['BId'];

              }
              $productBrand = Common::getMYsql()->getMultiList( self::TABLE_NAME , 'BId' , $brandId );

          }
          return $productBrand;
      }
     /**
     * 获取某个产品的品牌
     */
     public function getBrand( $BId){
         $Brand = Common::getMysql()->get( self::TABLE_NAME , array( 'BId' =>$BId));
         return $Brand['BName'];
     }
       /**
     * 获取某个产品的品牌信息
     */
     public function getBrandInfo( $BId){
         $Brand = Common::getMysql()->get( self::TABLE_NAME , array( 'BId' =>$BId));
         return $Brand;
     }
     /**
      * 根据产品品牌获得产品小类
      * @param type $bid
      * @return type 
      */
      public function getSCatByBrand( $bid ){
          $SCat = Common::getMysql()->get( self::TABLE_NAME_SEARCH , array( 'BId' => $bid ));
          return $SCat;
         
          
      }
     
      
}